﻿using System;
using UnityEngine;

namespace KuiHuaBaoDian.Services.Battle {

    /// <summary>
    /// 战斗地图位置
    /// </summary>
    public readonly struct BattleMapPosition {

        /// <summary>
        /// X
        /// </summary>
        public F64 X { get; init; }

        /// <summary>
        /// Y
        /// </summary>
        public F64 Y { get; init; }

        public override bool Equals(object obj) {
            if (obj is BattleMapPosition other) {
                return other.X == X && other.Y == Y;
            }
            return false;
        }

        public override int GetHashCode() => HashCode.Combine(X, Y);

        public override string ToString() => $"[{nameof(BattleMapPosition)}({nameof(X)}={X},{nameof(Y)}={Y})]";

        public static bool operator ==(BattleMapPosition left, BattleMapPosition right) => left.Equals(right);
        public static bool operator !=(BattleMapPosition left, BattleMapPosition right) => !left.Equals(right);

        public static implicit operator Vector2F64(BattleMapPosition @in) => new(@in.X, @in.Y);
        public static implicit operator Vector3F64(BattleMapPosition @in) => new(@in.X, @in.Y, F64.Zero);
        public static implicit operator Vector2(BattleMapPosition @in) => new(@in.X.Float, @in.Y.Float);
        public static implicit operator Vector3(BattleMapPosition @in) => new(@in.X.Float, @in.Y.Float, 0f);
        public static implicit operator BattleMapPosition(Vector2F64 @in) => new() { X = @in.X, Y = @in.Y };
        public static implicit operator BattleMapPosition(Vector3F64 @in) => new() { X = @in.X, Y = @in.Y };
        public static implicit operator BattleMapPosition(Vector2 @in) => new() { X = F64.From(@in.x), Y = F64.From(@in.y) };
        public static implicit operator BattleMapPosition(Vector3 @in) => new() { X = F64.From(@in.x), Y = F64.From(@in.y) };
    }
}
